package com.light.gulimall.order.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.light.gulimall.order.entity.OrderEntity;
import com.light.gulimall.order.service.OrderService;
import com.light.common.utils.PageUtils;
import com.light.common.utils.R;


/**
 * 订单
 *
 * @author minmin
 * @email 980680541@gmail.com
 * @date 2024-07-16 21:27:57
 */
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public void sendMessage() {
        for (int i = 0; i < 5; i++) {
            rabbitTemplate.convertAndSend("hello-java-exchange","hello.java","这是一个测试信息"+i);
        }
//        rabbitTemplate.convertAndSend("hello-java-topic-exchange", "java", "这是一个测试信息java");
//        rabbitTemplate.convertAndSend("hello-java-topic-exchange", "hello.world.java", "这是一个测试信息hello.world.java");
//        rabbitTemplate.convertAndSend("hello-java-topic-exchange", "hello.java", "这是一个测试信息hello.java");

    }

    @GetMapping("/ware/{orderSn}")
    public OrderEntity getOrder(@PathVariable("orderSn") String orderSn) {
        return orderService.getOne(new QueryWrapper<OrderEntity>().eq("order_sn",orderSn));
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderEntity order) {
        orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEntity order) {
        orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
